{layout name="layout/header" /}
<link href="root/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="root/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="root/css/plugins/datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet">
<link href="root/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet">
<link href="root/css/plugins/summernote/summernote.css" rel="stylesheet">
<link href="root/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
<link href="root/css/plugins/switchery/switchery.css" rel="stylesheet">
<script src="root/js/plugins/switchery/switchery.js"></script>
<div class="wrapper wrapper-content animated fadeInRight" id="app">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>{$title}</h5>
                </div>
                <div class="ibox-content">
                    <p>
                        <a type="button" class="btn btn-primary btn-outline" href="{:url('vote/index')}">返回列表</a>
                    </p>
                </div>
                <div class="ibox-content">
                    <form method="post" class="form-horizontal" id="form">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">活动名称</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="name" name="name">
                            </div>
                        </div>
                        <div class="form-group" v-if="id!=0">
                            <label class="col-sm-1 control-label">活动链接地址</label>
                            <div class="col-sm-11">
                                <p class="form-control-static">{{link_url}}</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">活动编号</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="act_id" name="act_id">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">详情页简介名称</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="detail_name" name="detail_name">
                                <span class="help-block m-b-none">比如 作品简介 学生简介</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">搜索框文字提示</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="search_words" name="search_words">
                                <span class="help-block m-b-none">首页搜索输入框中的文字提示</span>
                            </div>
                        </div>
<!--                        <div class="form-group">-->
<!--                            <label class="col-sm-1 control-label">是否允许web端投票</label>-->
<!--                            <div class="col-sm-10">-->
<!--                                <div class="radio i-checks">-->
<!--                                    <label><input type="radio" v-model="enable_web" value="1" name="enable_web"> <i></i>是</label>-->
<!--                                    <label><input type="radio" v-model="enable_web" value="0" name="enable_web"> <i></i>否</label>-->
<!--                                </div>-->
<!--                                <span class="help-block m-b-none">选 否 ，则只能在app内投票</span>-->

<!--                            </div>-->
<!--                        </div>-->
                        <div class="form-group">
                            <label class="col-sm-1 control-label">投票按钮文字</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="vote_btn_name" value="投票" name="vote_btn_name"> <i></i>投票</label>
                                    <label><input type="radio" v-model="vote_btn_name" value="点赞" name="vote_btn_name"> <i></i>点赞</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">是否分类</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="type_enable" value="1" name="type_enable"> <i></i>是</label>
                                    <label><input type="radio" v-model="type_enable" value="0" name="type_enable"> <i></i>否</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-1 control-label">投票时间</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control datetimepicker" id="start" name="start" data-id="start" v-model="start" placeholder="开始日期" readonly>
                            </div>
                            <div class="col-sm-3">
                                <input type="text" class="form-control datetimepicker" id="end" name="end" data-id="end" v-model="end" placeholder="截至日期" readonly>
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-1 control-label">限制类型</label>
                            <div class="col-sm-11">
                                <select class="form-control m-b" v-model="vote_type" name="vote_type">
                                    <option value="0">请选择</option>
                                    <option value="1">每天</option>
                                    <option value="2">每周</option>
                                    <option value="3">总数</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-1 control-label">按类型限制投票数</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="nums" name="nums">
                                <span class="help-block m-b-none">限制用户每天或每周能投的票数</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">每个作品最多投票数</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="per_nums" name="per_nums">
                                <span class="help-block m-b-none">限制单用户账号每天或每周给参赛作品最多能投的票数,0表示不限制</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">点击投票数</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="click_nums" name="click_nums">
                                <span class="help-block m-b-none">用户每次点击给参赛作品投出的票数</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">是否限制IP</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="is_ip" value="1" name="is_ip"> <i></i>是</label>
                                    <label><input type="radio" v-model="is_ip" value="0" name="is_ip"> <i></i>否</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">限制IP投票数</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="ip_nums" name="ip_nums">
                                <span class="help-block m-b-none">限制每个IP最多投票数,0代表禁止，同上面选否</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">是否限制设备唯一</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="is_device" value="1" name="is_device"> <i></i>是</label>
                                    <label><input type="radio" v-model="is_device" value="0" name="is_device"> <i></i>否</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">限制设备投票数</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="device_nums" name="device_nums">
                                <span class="help-block m-b-none">限制每个设备最大投票数,0代表禁止，同上面选否</span>
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-1 control-label">评论类型</label>
                            <div class="col-sm-11">
                                <select class="form-control m-b" v-model="comment_type" name="comment_type">
                                    <option value="0">请选择</option>
                                    <option value="1">百度自动审核</option>
<!--                                    <option value="2">手动审核</option>-->
                                    <option value="3">不允许评论</option>
                                </select>
                                <span class="help-block m-b-none">百度自动审核需要去系统设置对应参数</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">状态</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label><input type="radio" v-model="enable" value="1" name="enable"> <i></i>正常</label>
                                    <label><input type="radio" v-model="enable" value="0" name="enable"> <i></i>禁用</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">备注</label>
                            <div class="col-sm-11">
                                <input type="text" class="form-control" v-model="remark" name="remark">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">顶部图片</label>
                            <div class="col-sm-11">
                                <button class="btn btn-success product_upload_img" type="button">
                                    <i class="fa fa-upload"></i>&nbsp;&nbsp;<span class="bold">上传</span>
                                </button>
                                <input class="vue_img" type="file" style="display: none;" data-field="head_img"/>
                            </div>
                            <div class="col-sm-11 col-sm-offset-1 ">
                                <div class="row" id="imgs" v-if="head_img!=''">
                                    <div class="img_box col-xs-12 col-md-3" >
                                        <a class="fancybox" :href="head_img">
                                            <img alt="image" :src="head_img"/>
                                        </a>
                                        <a class="glyphicon glyphicon-trash" onclick="del_wx_img(this,'head_img');" :data-value="head_img"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">活动详情/规则</label>
                            <div class="col-sm-11">
                                <textarea class="form-control" style="display: none" v-model="info" name="info"></textarea>
                                <div class="ibox-content no-padding" >
                                    <div class="summernote" v-html="info" data-field="info">

                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <a class="btn btn-primary" @click="submit" type="submit">保存内容</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- iCheck -->
<script src="root/js/plugins/iCheck/icheck.min.js"></script>
<!--layer-->
<script src="root/js/plugins/datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="root/js/plugins/datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="root/js/plugins/validate/jquery.validate.min.js"></script>
<script src="root/js/plugins/validate/messages_zh.min.js"></script>

<script src="root/js/plugins/summernote/summernote.min.js"></script>
<script src="root/js/plugins/summernote/summernote-zh-CN.js"></script>
<script src="root/js/plugins/fancybox/jquery.fancybox.js"></script>

<script>
    var data = {$data};
    var url = "{$url}";
    if(data==1){
        data = {
            id:0,
            name:'',
            act_id:'',
            link_url:'',
            info:'',
            head_img:'',
            enable:1,
            start:'',
            end:'',
            vote_type:0,
            detail_name:'作品简介',
            nums:'',
            per_nums:0,
            click_nums:1,
            is_ip:0,
            ip_nums:0,
            is_device:0,
            device_nums:0,
            remark:'',
            comment_type:1,
            type_enable:0,
            search_words:'',
            vote_btn_name:'投票',
            enable_web:0,
        }
    }
    new Vue({
        el:"#app",
        data:data,
        methods:{
            submit:function () {
                $("#form").validate({
                    rules:{
                        name:{
                            required:true,
                        },
                        act_id:{
                            required:true,
                        },
                        info:{
                            required:true,
                        },
                        vote_type:{
                            min:1
                        },
                        nums:{
                            required:true,
                            digits:true,
                            min:0
                        },
                        ip_nums:{
                            digits:true,
                            min:0
                        },
                        device_nums:{
                            digits:true,
                            min:0
                        },
                        per_nums:{
                            required:true,
                            digits:true,
                        },
                        click_nums:{
                            required:true,
                            digits:true,
                            min:1
                        },
                        comment_type:{
                            required:true,
                            digits:true,
                            min:1
                        },
                        start:{
                            required:true,
                        },
                        end:{
                            required:true,
                        },
                    },
                    messages:{
                        vote_type:{
                            min:'请选择分类'
                        },
                        comment_type:{
                            min:'请选择评论类型'
                        },
                    }
                })
                if($("#form").valid()) {
                    if(data.head_img == ''){
                        layer.msg('顶部图片不能为空')
                        return ;
                    }

                    $.post(url,data,function (res) {
                        layer.msg(res.msg);
                    },'json')
                }

            }
        },
        mounted:function () {
            checks();
            $('.datetimepicker').datetimepicker({
                format:'yyyy-mm-dd hh:ii',
                language:  'zh-CN',
                weekStart: 1,
                todayBtn:  1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                forceParse: 0,
            });
            $('.fancybox').fancybox({
                openEffect: 'none',
                closeEffect: 'none'
            });
            $('.summernote').summernote({
                lang:'zh-CN',
                disableDragAndDrop: true,
                // 重写图片上传
                onImageUpload: function(files, editor, $editable) {
                    sendFile(files[0],editor,$editable);
                },
                onblur:function () {
                    var field = $(this).parent().prev().attr('data-field')
                    data[field] = $(this).code();
                }
            });
        }
    });
</script>

<script>
    $('input[name="enable"]').on('ifChecked', function(event){
        data.enable = $(this).val()
    });
    $('input[name="type_enable"]').on('ifChecked', function(event){
        data.type_enable = $(this).val()
    });
    $('input[name="is_ip"]').on('ifChecked', function(event){
        data.is_ip = $(this).val()
    });
    $('input[name="is_device"]').on('ifChecked', function(event){
        data.is_device = $(this).val()
    });
    $('input[name="vote_btn_name"]').on('ifChecked', function(event){
        data.vote_btn_name = $(this).val()
    });
    $('input[name="enable_web"]').on('ifChecked', function(event){
        data.enable_web = $(this).val()
    });
    $('#start').datetimepicker().on('hide', function (ev) {
        console.log($(this).val());
        var id = $(this).attr('data-id');
        data[id] = $(this).val();
    })
    $('#end').datetimepicker().on('hide', function (ev) {
        console.log($(this).val());
        var id = $(this).attr('data-id');
        data[id] = $(this).val();
    })
</script>
